// 饼图
import { ChartStrategy, EChartsOption } from "@@/composables/useECharts"
import { PieSeriesOption, TitleOption } from "echarts/types/dist/shared"

export class PieOptionStrategy implements ChartStrategy {
  getOptions(options: EChartsOption | null): EChartsOption {
    const title = options && (options.title as TitleOption)
    const series = options && (options.series as PieSeriesOption[]) && (options.series as PieSeriesOption)
    const resOptions: EChartsOption = {
      tooltip: {
        trigger: "item"
      },
      legend: {
        orient: "vertical",
        left: "left",
        textStyle: {
          fontSize: 16
        }
      },
      series: [
        {
          type: "pie",
          radius: "50%",
          data: [],
          emphasis: {
            itemStyle: {
              shadowBlur: 10,
              shadowOffsetX: 0,
              shadowColor: "rgba(0, 0, 0, 0.5)"
            }
          },
          label: {
            fontSize: 16
          }
        }
      ]
    }
    if (title && title.show) {
      resOptions.title = {
        left: "center",
        text: title && title.text ? title.text : ""
      }
    }
    if (series && series.center && resOptions.series) {
      ;(resOptions.series as PieSeriesOption[])[0].center = series.center
    }
    return resOptions
  }
}
